﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

using Longtop.Web.WebSite.Models;
using Castle.ActiveRecord;
using System.Threading;
using System.Globalization;
using Longtop.Web.WebSite.Shared;
using Longtop.Web.WebSite.Filters;
using Longtop.Web.SaleWeb.Models;
namespace Longtop.Web.SaleWeb.Controllers {
    
    [HandleError]
    public class ControllerBase : Longtop.Web.WebSite.ControllerBase {

        //protected override void OnActionExecuting(ActionExecutingContext filterContext) {
        //    //var lang = filterContext.RouteData.GetRequiredString("lang");

        //    //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
        //    //Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
        //    base.OnActionExecuting(filterContext);
        //}

        protected override ViewResult View(IView view, object model) {
            this.SetMasterPageModel(model);
            return base.View(view, model);
        }

        protected override ViewResult View(string viewName, string masterName, object model) {
            this.SetMasterPageModel(model);
            return base.View(viewName, masterName, model);
        }

        private void SetMasterPageModel(object model) {
            SiteMasterModel siteMasterModel = model as SiteMasterModel;
            if (siteMasterModel != null) {
                if (this.Identity.IsAuthenticated)
                    siteMasterModel.User = Sale.Find(this.Identity.Name);
            }
        }


    }
}
